﻿using System.Web.Mvc;
using LunchCommand.Services;
using LunchCommand.ViewModels;

namespace LunchCommand.Controllers
{
    public class HomeController : BaseController
    {
        private LunchService LunchService { get; set; }

        protected override void Initialize(System.Web.Routing.RequestContext context)
        {
            base.Initialize(context);
            this.LunchService = new LunchService(this.DatabaseContext, this.Settings, this.Logger);
        }

        [HttpGet]
        public ActionResult Index()
        {
            var viewModel = this.LunchService.GenerateViewModel(this.LunchUser);
            return View(viewModel);
        }

        [HttpGet]
        public ActionResult Algorithm()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index([Bind(Exclude = "User")]LunchCommandViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.User = this.LunchUser;
                this.LunchService.RehydrateAndProcessViewModel(ref viewModel);
            }

            return View(viewModel);
        }
    }
}